<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">      
    <h:head>
        <title>Gerar Notas</title>
    </h:head>
    <h:body>
        <ui:include src="../util/menu.xhtml"/>            
        <br/> 
        
        
        <p:messages autoUpdate="true" id="msg" />
        <h:form id="form"> 
            
            <p:confirmDialog global="true">
                <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" 
                    icon="ui-icon-check"/>
                <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" 
                    icon="ui-icon-close"/>
            </p:confirmDialog>                                            
            
            <p:panelGrid columns="2">
                 <f:facet name="header">
                        Cadastro de Notas
                 </f:facet>            

                <p:outputLabel value="Status"/>
                <p:outputLabel value="#{controllerMovNotas.status}"/>
                
                <p:outputLabel value="ID"/>
                <p:inputText value="#{controllerMovNotas.id}" disabled="true"/>                
                
                <p:outputLabel value="Escola"/>
                <p:selectOneMenu style="width: 300px" value="#{controllerMovNotas.escola}" required="true" requiredMessage="O campo Escola é obrigatório" disabled="#{controllerMovNotas.desabilita}">
                    <p:ajax  update="idSerie,:display"/>
                    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
                    <f:selectItems value="#{controllerMovNotas.retornaEscolas()}" var="escola" itemLabel="#{escola.nome}" itemValue="#{escola.id}"/>                                         
                </p:selectOneMenu>

                <p:outputLabel value="Série"/>
                <p:selectOneMenu style="width: 300px" id="idSerie" value="#{controllerMovNotas.serie}"  required="true" requiredMessage="O campo Série é obrigatório" disabled="#{controllerMovNotas.desabilita}">
                    <p:ajax update=":display"/>
                    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
                    <f:selectItems value="#{controllerMovNotas.retornaSerie()}" var="serie" itemLabel=" #{serie.descricao} /  #{serie.turma} / #{controllerMovNotas.converteTipoEnsino(serie.tipoEnsino)}" itemValue="#{serie.id}"/>                                                         
                </p:selectOneMenu>

                <p:outputLabel value="Matéria"/>
                <p:selectOneMenu style="width: 300px" id="materia" value="#{controllerMovNotas.materia}" required="true" requiredMessage="O campo Matéria é obrigatório!" disabled="#{controllerMovNotas.desabilita}">
                    <p:ajax update=":display"/>
                    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
                    <f:selectItems value="#{controllerMovNotas.retornaMateria()}" var="materia" itemLabel="#{materia.nome}" itemValue="#{materia.id}"/>                                                         
                </p:selectOneMenu>                
                
                <p:outputLabel value="Número"/>
                <p:spinner style="width: 300px" stepFactor="1" value="#{controllerMovNotas.numero}" required="true" requiredMessage="O campo Número é obrigatório!" disabled="#{controllerMovNotas.desabilita}"/>

                <p:outputLabel value="Nota"/>
                <p:spinner style="width: 300px" stepFactor="0.01" value="#{controllerMovNotas.nota}" required="true" requiredMessage="O campo Nota é obrigatório!" max="10" min="0"/>

                <f:facet name="footer">
                    <p:commandButton value="Novo" process="@this" actionListener="#{controllerMovNotas.novo()}" update="form"/>
                        <p:commandButton value="Salvar" actionListener="#{controllerMovNotas.gravar()}" update="form,:display"/>
                </f:facet>                           
            </p:panelGrid>
        </h:form>        
        
        <p:separator/>
        
        <h:form id="display">
            <p:dataTable value="#{controllerMovNotas.retornaNotas()}" var="nota"
                 paginator="true"
                 rows="9"
                 id="tabela">
                    <p:column headerText="Número">
                        <p:outputLabel value="#{nota.numero}"/>
                    </p:column>                           
                    <p:column headerText="Materia">
                        <p:outputLabel value="#{nota.materia.nome}"/>
                    </p:column>                                                
                    <p:column headerText="Nota">
                        <p:outputLabel value="#{nota.nota}"/>
                    </p:column>                                                
                    <p:column headerText="Ações">
                        <p:commandButton value="Excluir" action="#{controllerMovNotas.excluir(nota.id)}" process="@form,:display" update="@form,:display">
                            <p:confirm header="?" message="Deseja Excluir?" icon="ui-icon-alert" />
                        </p:commandButton>
                        <p:commandButton value="Alterar" actionListener="#{controllerMovNotas.alterar(nota.id)}" process="@form,:form" update=":form"/>                        
                    </p:column>                                                
            </p:dataTable>
        </h:form>
    </h:body>
</html>

